﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Definition"
	targetNamespace="http://www.baojiansoft.com/schemas/extensionmodel/statistic"
	elementFormDefault="qualified"
	xmlns="http://www.baojiansoft.com/schemas/extensionmodel/statistic"
	xmlns:mstns="http://tempuri.org/Definition.xsd"
	xmlns:xs="http://www.w3.org/2001/XMLSchema">

	<xs:element name="StatisticDefinition">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="Columns" type="StatisticColumnCollection" />
				<xs:element name="Rows" type="StatisticRowCollection" />
			</xs:sequence>
			<xs:attribute name="Name" type="RequiredString" use="required" />
			<xs:attribute name="Description" type="RequiredString" use="optional" />
		</xs:complexType>
	</xs:element>

	<xs:complexType name="StatisticColumnCollection">
		<xs:sequence>
			<xs:element ref="Filter" minOccurs="0" maxOccurs="unbounded" />
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="StatisticRowCollection">
		<xs:sequence>
			<xs:element ref="Filter" minOccurs="0" maxOccurs="unbounded" />
		</xs:sequence>
	</xs:complexType>

	<xs:element name="CandidateStatisticProperties" type="CandidateStatisticPropertyCollection" />

	<xs:complexType name="CandidateStatisticPropertyCollection">
		<xs:sequence>
			<xs:element name="Property" type="CandidateStatisticProperty" minOccurs="0" maxOccurs="unbounded" />
		</xs:sequence>
		<xs:attribute name="Name" type="RequiredString" use="required" />
	</xs:complexType>

	<xs:complexType name="CandidateStatisticProperty">
		<xs:all>
			<xs:element ref="DataSource" minOccurs="0" />

			<xs:element name="Algorithm" minOccurs="0">
				<xs:complexType>
					<xs:attribute name="Type" type="StatisticFilterAlgorithms" use="required">
						<xs:annotation>
							<xs:documentation>The algorithm of statistic filter.</xs:documentation>
						</xs:annotation>
					</xs:attribute>
					<xs:attribute name="Value" type="RequiredString" use="optional">
						<xs:annotation>
							<xs:documentation>Used to configure for special algorithm, like configuring a callback instance type for the type "Callback".</xs:documentation>
						</xs:annotation>
					</xs:attribute>
				</xs:complexType>
			</xs:element>
		</xs:all>
		<xs:attribute name="PropertyLabel" type="RequiredString" use="required">
			<xs:annotation>
				<xs:documentation>
					This is the understanding label for this candidate statistic property which may be helpful for users to easily configure statistic reports.
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="PropertyName" type="RequiredString" use="required">
			<xs:annotation>
				<xs:documentation>
					This indicates which property of input analyzing object will be used for statistic analysis.
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="PropertyType" type="PropertyTypes" use="required">
			<xs:annotation>
				<xs:documentation>
					This indicates the property type of input analyzing object.
					"String" means StatisticApi will convert not-listed property typed value to string for comparison/match.
					"Enumerable" means the property of input analyzing object is enumerable which implements interface IEnumerable.
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>

	<xs:element name="DataSource" type="CandidateStatisticPropertyDataSource" abstract="true"/>
	<xs:element name="Items" type="CandidateStatisticPropertyStaticDataSource" substitutionGroup="DataSource"/>
	<xs:element name="CallbackDataSource" type="CandidateStatisticPropertyCallbackDataSource" substitutionGroup="DataSource"/>

	<xs:complexType name="CandidateStatisticPropertyDataSource" abstract="true" />

	<xs:complexType name="CandidateStatisticPropertyStaticDataSource">
		<xs:complexContent>
			<xs:extension base="CandidateStatisticPropertyDataSource">
				<xs:sequence>
					<xs:element name="Item" type="StatisticItem" minOccurs="0" maxOccurs="unbounded" />
				</xs:sequence>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>

	<xs:complexType name="CandidateStatisticPropertyCallbackDataSource">
		<xs:complexContent>
			<xs:extension base="CandidateStatisticPropertyDataSource">
				<xs:attribute name="Type" type="RequiredString" use="required">
					<xs:annotation>
						<xs:documentation>
							Configure callback instance to resolve enumerable items for the property if it's Enumerable. The configured type must implement "BaoJianSoft.ExtensionModel.Statistic.ICandidateStatisticPropertyItemResolver".
						</xs:documentation>
					</xs:annotation>
				</xs:attribute>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>

	<xs:simpleType name="StatisticFilterAlgorithms">
		<xs:restriction base="xs:string">
			<xs:enumeration value="Contains">
				<xs:annotation>
					<xs:documentation>to check whether the analyzing property value contains configured value.</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="Contained">
				<xs:annotation>
					<xs:documentation>to check whether the analyzing property value is contained in configured value/values.</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="Equals">
				<xs:annotation>
					<xs:documentation>to check whether the analyzing property value equals to configured value.</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="Between">
				<xs:annotation>
					<xs:documentation>to check whether the analyzing property value is between configured max value and min value.</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="Aggregate">
				<xs:annotation>
					<xs:documentation>to calculate the statistic number by aggregating other statisic filters.</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="Callback">
				<xs:annotation>
					<xs:documentation>Configure callback instance to check whether the input analyzing data matches the statistic filter. The configured type must implement "BaoJianSoft.ExtensionModel.Statistic.IStatisticFilterCallback".</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>

	<xs:element name="Filter" type="StatisticFilter" abstract="true" />
	<xs:element name="Contains" type="ContainsStatisticFilter" substitutionGroup="Filter"/>
	<xs:element name="Contained" type="ContainedStatisticFilter" substitutionGroup="Filter"/>
	<xs:element name="Equals" type="EqualsStatisticFilter" substitutionGroup="Filter" />
	<xs:element name="Between" type="BetweenStatisticFilter" substitutionGroup="Filter" />
	<xs:element name="Callback" type="CallbackStatisticFilter" substitutionGroup="Filter" />

	<xs:complexType name="StatisticFilter" abstract="true">
		<xs:attribute name="PropertyName" type="RequiredString" use="required">
			<xs:annotation>
				<xs:documentation>
					This indicates which property of input analyzing object will be used for statistic analysis.
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="PropertyLabel" type="RequiredString" use="required">
			<xs:annotation>
				<xs:documentation>
					The label of property of input analyzing object will be used for statistic analysis.
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="PropertyType" type="PropertyTypes" use="required">
			<xs:annotation>
				<xs:documentation>
					This indicates the property type of input analyzing object.
					"String" means StatisticApi will convert not-listed property typed value to string for comparison/match.
					"Enumerable" means the property of input analyzing object is enumerable which implements interface IEnumerable.
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="HeaderText" type="RequiredString" use="required">
			<xs:annotation>
				<xs:documentation>
					The header text of statistic data in statistic report. It should be column header or row header depends on what type of the filter is (column/row).
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="Ordinal" type="xs:int" use="optional" default="999">
			<xs:annotation>
				<xs:documentation>
					The ordinal of statistic filter locates in statistic report.
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>

	<xs:complexType name="CallbackStatisticFilter">
		<xs:annotation>
			<xs:documentation>Configure callback instance to check whether the input analyzing data matches the statistic filter.</xs:documentation>
		</xs:annotation>
		<xs:complexContent>
			<xs:extension base="StatisticFilter">
				<xs:sequence>
					<xs:element name="Item" type="StatisticItem" minOccurs="0" maxOccurs="unbounded" />
				</xs:sequence>
				<xs:attribute name="CallbackType" type="RequiredString" use="required">
					<xs:annotation>
						<xs:documentation>
							The configured type must implement "BaoJianSoft.ExtensionModel.Statistic.IStatisticFilterCallback".
						</xs:documentation>
					</xs:annotation>
				</xs:attribute>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>

	<xs:complexType name="ContainsStatisticFilter">
		<xs:annotation>
			<xs:documentation>check whether the analyzing property value contains configured value.</xs:documentation>
		</xs:annotation>
		<xs:complexContent>
			<xs:extension base="StatisticFilter">
				<xs:sequence>
					<xs:element name="Item" type="StatisticItem" />
				</xs:sequence>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>

	<xs:complexType name="ContainedStatisticFilter">
		<xs:annotation>
			<xs:documentation>check whether the analyzing property value is contained in configured values.</xs:documentation>
		</xs:annotation>
		<xs:complexContent>
			<xs:extension base="StatisticFilter">
				<xs:sequence>
					<xs:element name="Item" type="StatisticItem" maxOccurs="unbounded" />
				</xs:sequence>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>

	<xs:complexType name="EqualsStatisticFilter">
		<xs:complexContent>
			<xs:extension base="StatisticFilter">
				<xs:sequence>
					<xs:element name="Item" type="StatisticItem" />
				</xs:sequence>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>

	<xs:complexType name="BetweenStatisticFilter">
		<xs:complexContent>
			<xs:extension base="StatisticFilter">
				<xs:sequence>
					<xs:element name="MinValue" type="RequiredString" minOccurs="0" />
					<xs:element name="MaxValue" type="RequiredString" minOccurs="0" />
				</xs:sequence>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>

	<xs:complexType name="AggregateStatisticFilter">
		<xs:annotation>
			<xs:documentation>The statistic filter is to aggregate the configuration columns.</xs:documentation>
		</xs:annotation>
		<xs:complexContent>
			<xs:extension base="StatisticFilter">
				<xs:sequence>
					<xs:element name="ReferencedFilter" type="AggregateReferencedFilter" minOccurs="1" maxOccurs="unbounded" />
				</xs:sequence>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>

	<xs:complexType name="AggregateReferencedFilter">
		<xs:annotation>
			<xs:documentation>The referenced statistic filters to aggregate filter.</xs:documentation>
		</xs:annotation>
		<xs:attribute name="HeaderText" type="RequiredString" use="required">
			<xs:annotation>
				<xs:documentation>The header text of referenced statistic filter. </xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>

	<xs:complexType name="StatisticItem">
		<xs:attribute name="Text" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation>
					The text to display when statistic filter matches the value.
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="Value" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation>
					The value for statistic filter to match.
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>

	<xs:simpleType name="PropertyTypes">
		<xs:restriction base="xs:string">
			<xs:enumeration value="String" />
			<xs:enumeration value="Decimal" />
			<xs:enumeration value="DateTime" />
			<xs:enumeration value="Integer" />
			<xs:enumeration value="Enumerable" />
		</xs:restriction>
	</xs:simpleType>

	<xs:simpleType name="RequiredString">
		<xs:restriction base="xs:string">
			<xs:minLength value="1" />
		</xs:restriction>
	</xs:simpleType>
</xs:schema>